

//
//  ZYNewListCommonCouseView.m
//  优学荟管理系统
//
//  Created by edz on 2018/1/9.
//  Copyright © 2018年 星道三好. All rights reserved.
//

#import "ZYNewListCommonCouseView.h"
#import "ZYNewListCommonCouseTwoCell.h"
#define kCell @"cell"
@interface ZYNewListCommonCouseView ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) NSMutableArray *dataSource;
@end

@implementation ZYNewListCommonCouseView

- (NSMutableArray *)dataSource{
    
    if (_dataSource == nil) {
        self.dataSource = [NSMutableArray array];
    }
    
    return _dataSource;
    
}



-(instancetype)initWithFrame:(CGRect)frame dataSource:(NSMutableArray *)dataArr{
    
    if (self = [super initWithFrame:frame]) {
        
        _dataSource= dataArr;
        
        
        
        
        self.backgroundColor = [UIColor whiteColor];
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.tableFooterView = [UIView new];
        _tableView.showsHorizontalScrollIndicator = YES;
        _tableView.showsVerticalScrollIndicator = YES;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self.tableView registerClass:[ZYNewListCommonCouseTwoCell  class] forCellReuseIdentifier:kCell];
        [self addSubview:_tableView];
        
        
        
    }
    return self;
}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataSource.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 50;
}



-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    ZYNewListCommonCouseTwoCell *cell = [tableView dequeueReusableCellWithIdentifier:kCell];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (self.dataSource.count > indexPath.row) {
        //        ZYTearchsModels *model = self.dataSource[indexPath.row];
        cell.teacherNameLabel.text = [self.dataSource[indexPath.row] valueForKey:@"petName"];
        //        [cell assignByZYTeacherAllsModel:model];
        
        
        [cell.studentButton addTarget:self action:@selector(studentButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
        
        
    }
    
    
    return cell;
}




- (void)studentButtonAction:(UIButton *)sender{
    ZYNewListCommonCouseTwoCell *cell = (ZYNewListCommonCouseTwoCell *)sender.superview.superview;
    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
    
    if (self.pushsBlock) {
        self.pushsBlock([NSString stringWithFormat:@"%@",[self.dataSource[indexPath.row] valueForKey:@"uid"]]);
    }
    
    
    
}




@end
